package com.blue.bluecode;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;


public class CheckBoxActivity extends Activity implements CompoundButton.OnCheckedChangeListener {

    private CheckBox cbApple,cbBanana,cbOrange;
    private TextView tvMultiChoose;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);
        getActionBar().setDisplayHomeAsUpEnabled(true);

        initView();
    }

    private void initView() {
        cbApple = (CheckBox) findViewById(R.id.cbApple);
        cbBanana = (CheckBox) findViewById(R.id.cbBanana);
        cbOrange = (CheckBox) findViewById(R.id.cbOrange);
        tvMultiChoose = (TextView) findViewById(R.id.tvMultiChoose);

        cbApple.setOnCheckedChangeListener(this);
        cbBanana.setOnCheckedChangeListener(this);
        cbOrange.setOnCheckedChangeListener(this);
        cbApple.setButtonDrawable(R.drawable.selector_checkbox);
    }


    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        StringBuffer str = new StringBuffer("您选择了:");
        if(cbApple.isChecked()){
            str.append("苹果 ");
        }
        if(cbBanana.isChecked()){
            str.append("香蕉 ");
        }
        if(cbOrange.isChecked()){
            str.append("橙子 ");
        }

        tvMultiChoose.setText(str);
    }
}
